package CTRLayer;

import DBLayer.*;
import ModelLayer.*;

/**
 * Write a description of class ProductCtr here.
 * 
 * @author (your name)
 * @version (a version number or a date)
 */
public class ProductCtr {
	// instance variables - replace the example below with your own

	/**
	 * Constructor for objects of class ProductCtr
	 */
	public ProductCtr() {
	}

	public void createProduct(String name, int purchasePrice,
			int salesPrice, String countryOfOrigin, int minStock, int stock,
			int productID) {

		Product productObj = new Product();

		productObj.setPName(name);
		productObj.setPurchasePrice(purchasePrice);
		productObj.setSalesPrice(salesPrice);
		productObj.setCountryOfOrigin(countryOfOrigin);
		productObj.setMinStock(minStock);
		productObj.setStock(stock);
		productObj.setProductId(productID);

		try {
			DbConnection1.startTransaction();
			DBProduct dbproduct = new DBProduct();
			dbproduct.insertProduct(productObj);
			DbConnection1.commitTransaction();
		} catch (Exception e) {
			DbConnection1.rollbackTransaction();
		}
	}

	public Product findProduct(int productID) {
		DBProduct dbproduct = new DBProduct();
		Product result = dbproduct.findProduct(productID, false);
		return result;
	}

	public void removeProduct(int productID) {
		DBProduct dbproduct = new DBProduct();
		dbproduct.delete(productID);
	}

	public int updateProduct(String name, int purchasePrice,
			int salesPrice, String countryOfOrigin, int minStock, int stock) {
		DBProduct dbproduct = new DBProduct();
		Product productObj = new Product();

		productObj.setPName(name);
		productObj.setPurchasePrice(purchasePrice);
		productObj.setSalesPrice(salesPrice);
		productObj.setCountryOfOrigin(countryOfOrigin);
		productObj.setMinStock(minStock);
		productObj.setStock(stock);
		return dbproduct.updateProduct(productObj);
		
	}
	// public void addVare(ArrayList vareList){}

}
